package thread2;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;

public class completeFuture4 {

    public static void main(String[] args) {
        CompletableFuture<String> future = CompletableFuture.supplyAsync(() -> {

            try {
                TimeUnit.SECONDS.sleep(5);
                System.out.println("future run end");
//                System.out.println(Thread.currentThread().getName());
                return "hello";
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        });

        CompletableFuture<Void> future1 = CompletableFuture.runAsync(() -> {
            try {
                TimeUnit.SECONDS.sleep(5);
                System.out.println("future1 run end");
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }).thenRun(()->{
            try {
                TimeUnit.SECONDS.sleep(5);
                System.out.println("then run end");
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        });

        future1.join();


        System.out.println(future.join());
    }
}
